package com.nut.spp.interceptor;

import com.nut.spp.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 统一拦截异常
 */
@RestControllerAdvice
@Slf4j
public class GlobalDefaultExceptionHandler {

    /**
     * 主动throw的异常
     * @param e
     * @return
     */
//    @ExceptionHandler(Exception.class)
//    @ResponseStatus(value = HttpStatus.OK)
//    public Result<?> handleUnProcessableServiceException(Exception e) {
//        log.info("global_error,", e);
//        return Result.fail(e.getMessage());
//    }
    @ExceptionHandler(Exception.class)
    @ResponseStatus(value = HttpStatus.OK)
    public Result<?> handleUnProcessableException(Exception e) {
        log.info("global_error", e);
        return Result.fail(e.getMessage());
    }

}
